/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bff.slimserver.musicjukebox.ui.components.favorites;

import com.bff.bjj.ui.component.MusicList;
import com.bff.slimserver.music.exceptions.PlaylistException;
import com.bff.slimserver.musicjukebox.lib.JukeboxProperties;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import org.bff.slimserver.SlimPlaylist;
import org.bff.slimserver.SlimRadioPlugin;
import org.bff.slimserver.exception.SlimConnectionException;
import org.bff.slimserver.musicobjects.SlimAlbum;
import org.bff.slimserver.musicobjects.radio.SlimAvailableRadio;

/**
 *
 * @author bfindeisen
 */
public class FavoritesList extends MusicList {

    private SlimRadioPlugin radioPlugin;
    private DefaultListModel radioListModel;
    private SlimPlaylist playlist;
    private FavoritesListCellRenderer radioListCellRenderer;
    private List<SlimAvailableRadio> radioList;

    public FavoritesList() {
        try {
            playlist = JukeboxProperties.getInstance().getPlaylist();
        } catch (PlaylistException ex) {
            Logger.getLogger(FavoritesList.class.getName()).log(Level.SEVERE, null, ex);
        }
        radioListModel = new DefaultListModel();
        try {
            setRadioPlugin(JukeboxProperties.getInstance().getRadioPlugin());
        } catch (SlimConnectionException ex) {
            Logger.getLogger(FavoritesList.class.getName()).log(Level.SEVERE, null, ex);
        }

        setRadioListCellRenderer(new FavoritesListCellRenderer());
        setCellRenderer(getRadioListCellRenderer());

        listAll();
        //addMouseListener(this);

    }


    public void listAll() {
        try {
            radioListModel.clear();
            
            radioList = new ArrayList<SlimAvailableRadio>(getRadioPlugin().getAvailableRadios());

            for (SlimAvailableRadio radio : radioList) {
                radioListModel.addElement(radio);
            }

            setModel(radioListModel);
            setSelectedIndex(0);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public SlimAlbum getSelectedAlbum() {
        return (SlimAlbum) getSelectedValue();
    }

    public SlimPlaylist getPlaylist() {
        return playlist;
    }

    public void setPlaylist(SlimPlaylist playlist) {
        this.playlist = playlist;
    }


    /**
     * @return the albumListCellRenderer
     */
    public FavoritesListCellRenderer getRadioListCellRenderer() {
        return radioListCellRenderer;
    }

    /**
     * @param radioListCellRenderer the radioListCellRenderer to set
     */
    public void setRadioListCellRenderer(FavoritesListCellRenderer radioListCellRenderer) {
        this.radioListCellRenderer = radioListCellRenderer;
    }

    /**
     * @return the radioPlugin
     */
    public SlimRadioPlugin getRadioPlugin() {
        return radioPlugin;
    }

    /**
     * @param radioPlugin the radioPlugin to set
     */
    public void setRadioPlugin(SlimRadioPlugin radioPlugin) {
        this.radioPlugin = radioPlugin;
    }
}
